<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的收藏</title>
</head>
<body>
<a href="my_favorite_list.html"><input type="button" value="管理"></a><br>
<hr>
<div id="myFavorites"></div>

<script src="../js/axios-0.18.0.js"></script>
<script>
    //1. 当页面加载完成后，发送ajax请求
    window.onload = function () {
        //2. 发送ajax请求
        axios({
            method:"get",
            url:"getMyFavorites"
        }).then(function (resp) {
            //获取数据
            let map = resp.data;
            console.log(map);
            let myFavorites = "";
            Object.entries(map).forEach(([category,favorites]) =>{
                myFavorites +="<p>"+category+"</p>";
                for (let i = 0; i < favorites.length ; i++) {
                    let obj = favorites[i];

                    myFavorites += "<span><a href="+obj.linkUrl+" target=\"_blank\">"+obj.favoriteName+"</a></span>|";
                }
            });


            // 设置表格数据
            document.getElementById("myFavorites").innerHTML = myFavorites;
        })
    }
</script>
</body>
</html>